package com.prs.crm.action.approval;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.courser.struts.BaseAction;
import org.courser.ui.PaginationSupport;
import org.hibernate.criterion.DetachedCriteria;

import com.prs.crm.domain.approval.ProcessType;
import com.prs.crm.domain.approval.ShenQingType;
import com.prs.crm.service.approval.ProcessTypeService;

public class ProcessTypeAction extends BaseAction{
	private PaginationSupport pagination;
	private Integer[] ids;
	private ProcessTypeService processTypeService;
	private ProcessType processType;
	public PaginationSupport getPagination() {
		return pagination;
	}
	public void setPagination(PaginationSupport pagination) {
		this.pagination = pagination;
	}
	public Integer[] getIds() {
		return ids;
	}
	public void setIds(Integer[] ids) {
		this.ids = ids;
	}
	public ProcessTypeService getProcessTypeService() {
		return processTypeService;
	}
	public void setProcessTypeService(ProcessTypeService processTypeService) {
		this.processTypeService = processTypeService;
	}
	public ProcessType getProcessType() {
		return processType;
	}
	public void setProcessType(ProcessType processType) {
		this.processType = processType;
	}
	/********************************************************************/
	@Action("listProcessType")
	public String listProcessType(){
		DetachedCriteria criteria = this.getPaginationHelper().createQuery(ProcessType.class);
		this.setPagination(this.processTypeService.listByPage(criteria, 
				this.getPaginationHelper().prepare(pagination)));
		return SUCCESS;
	}
	@Action("editProcessType")
	public String editProcessType(){
		return SUCCESS;
	}
	@Action(value="saveProcessType",results={
			@Result(name="success",type="redirect",location="listProcessType"),
			@Result(name="error",type="chain",location="editProcessType")
	})
	public String saveProcessType(){
		if(processType.getName() == null || "".equals(processType.getName().trim())){
			addActionError("名称不能为空!");
			return ERROR;
		}
		this.processTypeService.save(processType);
		return SUCCESS;
	}
	@Action(value="removeProcessType",results={
			@Result(name="success",type="redirect",location="listProcessType"),
			@Result(name="error",type="chain",location="listProcessType")
	})
	public String removeProcessType(){
		if(ids==null){
			this.setPrompt("请选择要删除的数据行！");
			return ERROR;
		}
		this.processTypeService.batchRemove(ids);
		return SUCCESS;
	}
}
